package com.hc.weatherhc.service;

import com.hc.weatherhc.domain.WeatherResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class WeatherService {
    @Autowired
    RestTemplate restTemplate;

    public WeatherResponse fetchWeatherData(String cityId) {
        // 修复：将 city 改为 cityId (使用正确的参数名)
        WeatherResponse result = restTemplate.getForObject(
                "https://apis.tianapi.com/tianqi/index?key=2af8ed08605c20f76f8183d1b702474b&city="
                        + cityId + "&type=7",
                WeatherResponse.class
        );
        return result;
    }
}